

void setup() 
{
  size(700, 700);
  colorMode(RGB, 360, height, height);  
  //noStroke();
}
void draw()
{
  if (mousePressed && (mouseButton == LEFT)) {
    background(random(255),random(255),random(255));
    int numLines = 3;
    int j;
    LinePattern plaidPattern = new LinePattern(numLines);
    for(j=0;j<numLines;j++)
    {
      plaidPattern.Stripes[j].layStripe();
    }
  }
}



class LinePattern
{
  int maxdisplacement;
  int patdisplacement;
  int patnum;
  int numStripes;
  int i;
  Stripe[] Stripes;
  LinePattern(int numStripes)
  {
    Stripes = new Stripe[numStripes];
    i = 0;
    this.numStripes = numStripes;
    for(i=0; i<numStripes; i++)
    {
      Stripes[i] = new Stripe(i);
    }
    patnum = ((int) random(5,10));
    patdisplacement = height/patnum;
    while(patdisplacement < maxdisplacement)
    {
      patnum = ((int) random(10));
      patdisplacement = height/patnum;
    } 
  }
  class Stripe
  {
    int r;
    int b;
    int g;
    int lwidth;
    int ldisplacement;
    int lgravity;
    int l = 0;
    int s;
    int coord1;
    int coord2;
    boolean centerLine;
 
    Stripe(int numline)
    {
      r = (int) random(255);
      b = (int) random(255);
      g = (int) random(255);
      lwidth = (int) random(10);
      lgravity = numline;
      if(numline==0)
      { 
        ldisplacement = 0;
      } else
      {
        ldisplacement = (int) random(25);
        if(ldisplacement>maxdisplacement) maxdisplacement = ldisplacement;
      }
    }
    void layStripe()
    {
      stroke(r,g,b);
      for(l=0;l<patnum;l++)
      {
        for(s=-lwidth/2; s<lwidth/2; s++)
        {
          coord1 = s+ldisplacement+patdisplacement*l+patdisplacement/2;
          coord2 = s-ldisplacement+patdisplacement*l+patdisplacement/2;
          line(coord1, height, coord1, 0);
          line(coord2, height, coord2, 0);
          line(height, coord1, 0, coord1);
          line(height, coord2, 0, coord2);
        }
      }
    }
  }
}
